package com.polaris.live.ui.message.widget.single_message

import android.text.SpannableStringBuilder
import com.blankj.utilcode.util.SpanUtils
import com.blankj.utilcode.util.StringUtils
import com.polaris.live.R
import com.polaris.live.adapter.MessageAdapter
import com.polaris.live.common.cacha.UserManager
import com.polaris.live.databinding.MessageNotHaveBinding
import com.polaris.live.im.db.entity.MessageEntity
import com.polaris.live.translation.R.string

/**
 * 不支持的
 *
 * @author Created by lucas on 2023/10/21 15:11
 * @since 1.0.0
 */
class MessageNotHaveItemHolder(
    adapter: MessageAdapter,
    binding: MessageNotHaveBinding
) : AbstractMessageItemHolder<MessageNotHaveBinding>(adapter, binding) {

    override fun bind(item: MessageEntity) {
        mBinding.apply {
            bindCommon(
                item,
                layoutTime.messageTextTime,
                layoutLeft,
                layoutRight,
                layoutLeftAvatar.avAvatar,
                layoutRightAvatar.avAvatar,
                layoutLeftAvatar.avFv,
                layoutRightAvatar.avFv,
                null, null
            )
        }

        if (item.sender == UserManager.getUser().userId) {
            setTextRight(item)
        } else {
            setTextLeft(item)
        }
    }

    private fun setTextLeft(item: MessageEntity) {
        mBinding.messageTextLeftText.text = spannableStringBuilder()

    }

    private fun setTextRight(item: MessageEntity) {
        mBinding.rightContent.text = spannableStringBuilder()
    }

    private fun spannableStringBuilder(): SpannableStringBuilder? {
        return SpanUtils.with(mBinding.messageTextLeftText)
            .appendImage(R.drawable.message_item_state_not_have, SpanUtils.ALIGN_CENTER)
            .append(" ${StringUtils.getString(string.session_content_unsupported)}")
            .create()
    }

}